﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;

/// <summary>
/// CommonHelper 的摘要说明
/// </summary>
public class CommonHelper
{
    /// <summary>
    /// 截取字符串长度
    /// </summary>
    /// <param name="strChar"></param>
    /// <param name="intLength"></param>
    /// <returns></returns>
    public static string CutChar(string strChar, int intLength)
    {
        //取得自定义长度的字符串
        if (strChar.Length > intLength)
            return strChar.Substring(0, intLength);
        else
            return strChar;
    }

    /// <summary>
    /// 通过SqlDataAdapter获取数据
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    public static DataSet GetDataByAdapter(string sql)
    {
        SqlConnection con = new SqlConnection(SqlHelper.connstring);
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter(sql, con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        con.Close();
        return ds;
    }

    /// <summary>
    /// 执行sql语句无返回值
    /// </summary>
    /// <param name="sql"></param>
    public static void ExecuteSql(string sql)
    {
        SqlHelper helper = new SqlHelper();
        helper.RunSql(sql);
    }
}